<?php 

/**
上传类
**/
class Upload{
  	private  $path;//路径

  	public function __construct($path = './'){
		$this->path = $path;
	}

	// 外部调用的上传方法
	public  function up(){

		$temArr = $this->_restArr();//重组数据
		// var_dump($temArr);
		$this->_moveFlie($temArr);//移动文件
	}

	// 移动文件的方法
	private  function _moveFlie($temArr){
		foreach ($temArr as $key => $value) {
			if(is_uploaded_file($value['tmp_name'])){

				$fileName = time()."$key".".png";
				$date = date('Y-m-d');
				$destinUrl = "$this->path"."/".$date."/".$fileName;
				// var_dump()
				is_dir($this->path."/".$date) || mkdir($this->path."/".$date,777,TRUE);

				move_uploaded_file($value['tmp_name'],$destinUrl);
			}else{
				echo '你的操作不合法';
			};
		}	
	}

	// 重组数组的方法
	private  function _restArr(){
		$data = $_FILES;
		$emptyArr = array();
		foreach ($data['userfile'] as $key => $value) {
			foreach ( $value as $k => $v) {
				$emptyArr[$k][$key] = $v;
			}
		}
		return $emptyArr;
	}
}


 ?>